package com.voltmao.controller.module.intent;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.voltmao.service.application.intent.IntentUserAgainServiceImpl;
import com.voltmao.webpro.frame.analyze.DTOSmith;
import com.voltmao.webpro.frame.dto.ApiResult;
import com.voltmao.webpro.frame.dto.DataPage;
import com.voltmao.webpro.frame.dto.GridViewResult;
import com.voltmao.webpro.frame.dto.status.Constants;
import com.voltmao.webpro.frame.exception.WebProViewException;
import com.voltmao.webpro.utils.http.HttpRequestUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 跟进记录控制层
 * @author zya
 */
@Controller
@RequestMapping(value = "/module/intent/again")
public class IntentAgainController {
    @Autowired
    IntentUserAgainServiceImpl intentUserAgainService;

    /**
     * 业务员新增或更新跟进记录
     * @param request
     * @return
     */
    @RequestMapping(value = "/insertOrUpdate.json")
    @ResponseBody
    public ApiResult insertOrUpdate(HttpServletRequest request){
        return new DTOSmith(request).builderApiResult(new DTOSmith.ApiLoadBackCall() {
            @Override
            public Object resultData(HttpServletRequest request, ApiResult apiResult) throws WebProViewException {
                Map<String, Object> params = HttpRequestUtil.getParameterMap(request);
                try {
                    return intentUserAgainService.insertOrUpdate(params);
                }catch (Exception e){
                    apiResult.setStatus(Constants.PARAMETER_ERROR);
                    return e.getMessage();
                }
            }
        });
    }

    /**
     * 获取业务对某个意向渠道的跟进记录列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/visitRecodes.json")
    @ResponseBody
    public GridViewResult getVisitRecodes(HttpServletRequest request){
        return new DTOSmith(request).builderSeachGridResult(new DTOSmith.SeachGridBackCall() {
            @Override
            public DataPage resultData(HttpServletRequest request, GridViewResult apiResult) throws WebProViewException {
                apiResult.dataUrl="/again/visitRecodes.json";
                Map<String, Object> params = HttpRequestUtil.getParameterMap(request);
                return intentUserAgainService.getVisitRecodes(params);
            }
        });
    }



}
